Websydian v6.1 online documentationOnline documentation - WebsydianExpress v3.5

ExtAssociationSelect Sample Description

Overview

This describes a simple example of how you can use functions that inherit from ExtAssociationSelect in your applications.

the association select entity is used when you want to associate multiple records in one entity to one record in another entity.

An implementation of the sample can be found in the EXPRESSTEST model.

A running version of the sample can be found in the delivered sample site.

Sample content

The sample shows an implementation of an entity inheriting from ExtAssociationSelect.

Implementing the sample

The maintenance functionality is implemented for the AlbumCollection.UserFavoritAlbums entity.

Defining inheritance for the entity

To get the edit suite functions and define the primary and secondary entities, specify the following inheritance:

Source Object Verb Target Object
AlbumCollection.UserFavoritAlbums is a ENT WSYEXTJS/ExtAssociationSelect
AlbumCollection.UserFavoritAlbums replaces ENT

...by ENT

FOUNDATI/Owner

WrappedUser

AlbumCollection.UserFavoritAlbums

 

replaces ENT

...by ENT

FOUNDATI/Owner2

AlbumCollection.Albums

This adds a set of scoped functions to the entity - the top function is: AlbumCollection.UserFavoritAlbums.ExtAssociationSelector.

The fully implemented selector looks like this:

The top section shows data for the one record of the primary entity which the selected records of the secondary entity will be associated with when they are selected.

This is loaded by the function AlbumCollection.UserFavoritAlbums.ExtAssociationSelector.Selector, which is also the parent page for the two grids shown below the detail information. In this case, this is information about a user.

The left grid shows all records in the secondary entity that can be associated with the record of the primary entity shown above. Records already associated with the user is not shown. In this case, this list shows all the records in the album table.

The left grid is loaded by the function: AlbumCollection.UserFavoritAlbums.ExtAssociationSelector.Selector.ChildGridSelectable

The right grid shows all records in the secondary entity that is associated with the record from the primary entity - in this case it is the user's favorite albums.

The right grid is loaded by the function: AlbumCollection.UserFavoritAlbums.ExtAssociationSelector.Selector.ChildGridSelected.

Note that the user entity isn't a standard relational table, instead we've just used the WebsydianExpress APIs to create an entity that can be used instead of a "normal" entity.

Defining the grid sort order

The album entity has a UUID as the primary key. This is not a useful sort order for the right grid, so the view used by the right grid must be replaced as well as the function used to retrieve the records:

Source Object Verb Target Object
AlbumCollection.UserFavoritAlbums.ExtAssociationSelector replaces VW

...by VW

FOUNDATI/Owner2.Fetch

AlbumCollection.UserFavoritAlbums.byAlbum

AlbumCollection.UserFavoritAlbums.ExtAssociationSelector replaces FNC

...by FNC

FOUNDATI/Owner2.Fetch.BlockFetch

AlbumCollection.Albums.FetchByAlbum.BlockFetchRRNWrapper

The view used by the right grid is based on the association entity (AlbumCollection.UserFavoritAlbums). This must show all albums selected by the current user.

This means that the view must have the user as the first key:

Source Object Verb Target Object
AlbumCollection.UserFavoritAlbums.ExtAssociationSelector replaces VW

...by VW

FOUNDATI/Owner2.Fetch

AlbumCollection.UserFavoritAlbums.byAlbum

Defining grid fields

The left grid shows the albums you are able to select. There is no reason to let this grid contain all fields from the Album entity. The following triples removes the fields that should not be shown:

Source Object Verb Target Object
AlbumCollection.UserFavoritAlbums.ExtAssociationSelector.Selector.ChildGridSelectable local FLD

...for VAR

AlbumCollection.Fields.UUIDAlbum

OmitGridFields

AlbumCollection.UserFavoritAlbums.ExtAssociationSelector.Selector.ChildGridSelectable local FLD

...for VAR

AlbumCollection.Fields.AlbumArtURL

OmitGridFields

AlbumCollection.UserFavoritAlbums.ExtAssociationSelector.Selector.ChildGridSelectable local FLD

...for VAR

AlbumCollection.Fields.AlbumFormat

OmitGridFields

AlbumCollection.UserFavoritAlbums.ExtAssociationSelector.Selector.ChildGridSelectable local FLD

...for VAR

AlbumCollection.Fields.AlbumReview

OmitGridFields

AlbumCollection.UserFavoritAlbums.ExtAssociationSelector.Selector.ChildGridSelectable local FLD

...for VAR

AlbumCollection.Fields.AlbumReleaseYear

OmitGridFields

For the right grid, the user surrogate should not be shown - as it would be the same for all the records. On the other hand, information about the album should be retrieved from the Album entity and added to each record. The following triples removes the user surrogate and adds the additional information to the grid:

Source Object Verb Target Object
AlbumCollection.UserFavoritAlbums.ExtAssociationSelector.Selector.ChildGridSelected local FLD

...for VAR

WSYAPI/APIFields.UserSurrogate

OmitGridFields

AlbumCollection.UserFavoritAlbums.ExtAssociationSelector.Selector.ChildGridSelected local FLD

...for VAR

AlbumCollection.Fields.AlbumName

WsyGrid

AlbumCollection.UserFavoritAlbums.ExtAssociationSelector.Selector.ChildGridSelected local FLD

...for VAR

AlbumCollection.Fields.AlbumArtist

WsyGrid

Coding the functionality

Most of the necessary functionality is implemented by the pattern itself, however, there are a couple of details that needs to be handled.

ProcessEntryPoint Code

First, the selector (AlbumCollection.UserFavoritAlbums.ExtAssociationSelector.Selector) needs to get the identification of the user as input. In many cases, the selector will be called from a detail page showing the records that you want to associate the records in the secondary entity to. But in this case the record is the current user - so we have to retrieve this information in the ProcessEntryPoint.

The following code is entered in the Pre point "Call to first PageGenerator" in AlbumCollection.UserFavoritAlbums.ExtAssociationSelector:

Call WSYAPI/APIServer.Session.ServerGetCurrentSessionID

Call WSYAPI/APIServer.Session.GetBasicSessionData

Map with:

 APIServer.Session.ServerGetCurrentSessionID/Output<APIFields.SessionSurrogate>

Set WebInput<APIFields.UserSurrogate> = APIServer.Session.GetBasicSessionData/Output<APIFields.UserSurrogate>

 

Data in the WebInput variable is automatically added as input to the call of the selector PageGenerator.

Selector function code

The local modifications in the PageGenerator handles the situation where no user is logged in. In a real life application, this business process would not be available for anonymous sessions - but to make the sample available (and visible in the menu) without logging in, a default user is assigned if no user surrogate is specified in the input. This is not really relevant for the sample - so the code will not be explained here.

ChildGridSelected code

This child grid page shows information about the selected albums. This uses the AlbumCollection.UserFavoritAlbums.byAlbum view to retrieve information about which albums the current user has selected. This view only contains the unique identification of the album. To retrieve the name and artist information, the following code has been added to the Pre Point "Process grid data" (See the example model for a full implementation including error handling):

Call AlbumCollection.Albums.Fetch.SingleFetch

Map with:

WsyGrid<AlbumCollection.Fields.UUIDAlbum>

Set WsyGrid<AlbumCollection.Fields.AlbumName> = AlbumCollection.Albums.Fetch.SingleFetch/FetchedData<AlbumCollection.Fields.AlbumName>

Set WsyGrid<AlbumCollection.Fields.AlbumArtist> = AlbumCollection.Albums.Fetch.SingleFetch/FetchedData<AlbumCollection.Fields.AlbumArtist>
 

Generate and build

Generate and build the ExtAssociationSelector function, run all _CreateTemplates functions.

Deploy the functions and templates.

Define the ProcessEntryPoint and add it to the site structure.